<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Form</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link href="/sap/demo.css" rel="stylesheet" type="text/css" />
    <script src="/sap/scripts/boot.js" type="text/javascript"></script>
</head>
<style>
    td{
        margin-top:10px;
    }
</style>

<body>

<div id="form1" >
    <table cellspacing='10' style="width: 700px; border-spacing:0px 10px;" >

        <tr>
            <td>
                <label for="textbox1$text">选择平台：</label>
            </td>
            <td>
                <input id="btnEdit1" required="true" class="mini-buttonedit" onbuttonclick="onButtonEdit" name="" textName="" style="width: 250px"/>
            </td>
        </tr>

        <!--<tr>-->
            <!--<td>-->
                <!--<label for="textbox1$text">通知类型：</label>-->
            <!--</td>-->
            <!--<td>-->
                <!--<select class="mini-combobox" name="type" id="type">-->
                    <!--<option value="0">普通</option>-->
                    <!--<option value="1">活动</option>-->
                <!--</select>-->
            <!--</td>-->
        <!--</tr>-->

        <tr>
            <td>
                <label for="textbox1$text">清单名称：</label>
            </td>
            <td>
                <input id="textbox1"  name="name" class="mini-textbox" required="true" width='250px' value =""/>
            </td>
        </tr>

        <tr>
            <td colspan="2" align="center">
                <a class='mini-button' onclick="submitForm(1)" >保存</a>
                <a class='mini-button' onclick="onCancel()" >取消</a>
            </td>
        </tr>

    </table>
</div>

<script type="application/javascript">

    mini.parse();

    function onOk() {
        CloseWindow("ok");
    }
    function onCancel() {
        CloseWindow("cancel");
    }

    function submitForm(tag) {
        //提交表单数据
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) return;

        //确认提示
        mini.confirm("确定创建？", "确定？",
            function (action) {
                if (action == "ok") {
                    var data = form.getData();      //获取表单多个控件的数据
                    addlistData.type = data.type;
                    addlistData.name = data.name;

                    var json = mini.encode(addlistData);   //序列化成JSON

                    $.ajax({
                        url: "/Shelves/saveshelvesList",
                        type: "post",
                        data: { savedata:json },
                        dataType:'json',
                        success: function (data) {
                            if(data.code!=0){
                                //mini.alert('添加成功');
                                self.parent.location.href = "/index.php?m=&c=Shelves&a=shelvesNotice&listid="+data.code;
                            }


                        }
                    });

                } else {
                }
            });

        // save end

    }

    var addlistData = null;

    function onButtonEdit(e) {
        var btnEdit = this;

        mini.open({
            url:  "/Shelves/select",
            title: "选择平台",
            width: 650,
            height: 380,
            ondestroy: function (action) {

                if (action == "ok") {
                    var iframe = this.getIFrameEl();
                    var data = iframe.contentWindow.GetData();
                    data = mini.clone(data);
                    addlistData = data;
                    mini.get('btnEdit1').setText(data.text);
                    mini.get('btnEdit1').setValue(data.id);

                }
            }
        });

    }

    function CloseWindow(action) {
        if (action == 'ok'){
            //self.parent.location.href = "/index.php?m=&c=Shelves&a=shelvesNotice";
        }else {
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }

    }

</script>

</body>

</html>